

function say() {
    alert("LC:452. 用最少数量的箭引爆气球");
}
say();

/**
 * @param {number[][]} points
 * @return {number}
 */
var findMinArrowShots = function(points) {
    //12:45-1:00
    //数组总长度-交叉的数量 跟435是同一题的解法
    if(points.length == 0){
        return 0
    }
    sort(points) //TODO:优化

    var count = 0
    var end = points[0][1]
    for(var i = 1; i < points.length; i ++){
        var item = points[i]
        if(item[0] <= end){ //有交叉
            end = Math.min(end, item[1])
            count++
        }else { //没交叉
            end = item[1]
        }
    }

    return points.length - count
};

function sort(arr){
    for(var i = 0; i < arr.length; i++){
        for(var j = 0; j < arr.length - 1 - i; j++){
            var item = arr[j]
            var next = arr[j + 1]
            if(item[0] > next[0]){
                arr[j] = arr[j + 1]
                arr[j + 1] = item
            }
        }
    }
}
